import { createRouter, createWebHistory,createWebHashHistory  } from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store/index.js'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/search',
    name: 'Search',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Search.vue')
  },
  {
    path: '/user',
    name: 'User',
    beforeEnter:(to,from,next)=>{
      // console.log(store.state.user);
      if (store.state.user.isLogin) {
        next();
      }else{
        next('/login')
      }
      
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/User.vue')
  },
  {
    path: "/search/:key", 
    name: 'SearchList', 
    component: () => import(/* webpackChunkName: "about" */ '../views/SearchList.vue')
  },
  {
    path: "/login", 
    name: 'Login', 
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
  {
    path: "/register", 
    name: 'Register', 
    component: () => import(/* webpackChunkName: "about" */ '../views/Register.vue')
  },
  {
    path: "/addlost", 
    name: 'addLost', 
    component: () => import(/* webpackChunkName: "about" */ '../views/AddLost.vue')
  },
  {
    path: "/changeList/:no", 
    name: 'changeList', 
    component: () => import(/* webpackChunkName: "about" */ '../views/Changelist.vue')
  },
  {
    path: "/changeUser/:email", 
    name: 'changeUser', 
    component: () => import(/* webpackChunkName: "about" */ '../views/Changeuser.vue')
  },
  {
    path: "/detail/:no", 
    name: 'detail', 
    component: () => import(/* webpackChunkName: "about" */ '../views/details.vue')
  },
]

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL),
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

export default router
